import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from "path";
import Components from 'unplugin-vue-components/vite';
import {VantResolver} from '@vant/auto-import-resolver';

// https://vitejs.dev/config/

/** 路径查找 */
const pathResolve = (dir: string): string => {
    return resolve(__dirname, ".", dir);
};

/** 设置别名 */
const alias: Record<string, string> = {
    "@": pathResolve("src"),
    "@build": pathResolve("build")
};

export default defineConfig({
    base: '/loan/',
    build: {
        outDir: 'loan-dist',
    },
    plugins: [
        vue(),
        Components({
            resolvers: [VantResolver()],
        })
    ],
    resolve: {
        alias
    }
    ,
    // 服务端渲染
    server: {
        // 是否开启 https
        host: "0.0.0.0",
        // 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
        proxy: {
            "/app": {
                // 正式环境
                target: "http://124.221.247.157:8090/",
                // 家装环境
                // target: "http://192.168.31.143:8090",
                // 公司环境
                // target: "http://192.168.21.25:8090",
                changeOrigin: true,
                // 截取路径，拼接后端接口
                rewrite: path => path.replace(/^\/app/, "")
            }
        }
    },
})
